<include file="Common:header" />
<TYcss file='cropper.min'/>
<TYjs file='cropper.min'/>

<div class="table_content">
    <form action="{:U(MODULE_NAME.'/role/add_admin')}" id="addUserForm" method="post" class="ajax_form" jsonStr="urlJson">
        <script type="text/javascript">
        </script>
        <table class="edit_table">
            <tr>
                <td class="tablehead">账号</td>
                <td><input type="text" name="user_name" value="" class="text w150 required"/><label class="tips"></label></td>
            </tr>
                <tr>
                    <td class="tablehead">密码</td>
                    <td><input type="password" name="password" placeholder="" class="text w150 required"/></td>
                </tr>
                <tr>
                    <td class="tablehead">确认密码</td>
                    <td><input type="password" name="repassword" class="text w150 required"/><label class="tips"></label></td>
                </tr>
            <tr>
            	<td class="tablehead">管理员等级</td>
            	<td>
            		<select id="rold_id" name="rold_id">
            		<foreach name="roleList" item="vo">
            			<option value="{$vo['id']}">{$vo['name']}</option>
            		</foreach>
            		</select>
            	</td>
            </tr>
            <tr class="agent">
            	<td class="tablehead">收益占比</td>
            	<td>
            		<input type="text" name="proportion" style="width:50px;height:30px;text-align:center;"/> %
            	</td>
            </tr>
            <tr class="agent">
            	<td class="tablehead">选择代理城市</td>
            	<td>
            	<select class="weui-select selectProvince" name="provinceID">
                    <option value="">--请选择--</option>
	        		<foreach name="province" item="so" >
						<option value="{$so.provinceid}">{$so.provincename}</option>
					</foreach>
                </select><br/>
                <div class="selectCity"></div>
            	</td>
            </tr>
            <tr>
            	<td class="tablehead">备注</td>
            	<td><textarea name="about" style="width:400px;height:200px"/></textarea></td>
            </tr>
            
            <tr>
                <td class="tablehead">
                </td>
                <td>
                	<input type="hidden" name="city_id" class="city_id"/>
                    <input type="button" class="save_btn" value="保存"/>
                    <input type="button" class="back_btn" value="返回"/>
                </td>
            </tr>
        </table>
    </form>
</div>

<script type="text/javascript">
$('.agent').hide();
$('#rold_id').change(function(){
	if($(this).val() == '5'){
		$('.agent').show();
	}else{
		$('.agent').hide();
	}
});
var cityData = <?php echo json_encode($city);?>;
var savePostData = {};
var num = 1;
//选择省份触发市区
$(".selectProvince").on('change', function() {
	savePostData.proVal = $(".selectProvince").val();
	var cityHtml = "";
	$.each(cityData,function(index, el) {
		if (el.provinceid==savePostData.proVal) { //符合对应的【省份】
			if(num % 5 == 0){
				cityHtml += "<input type='checkbox' class='citycheck' value=\""+el.cityid+"\">"+el.cityname+"&nbsp;&nbsp;<br/>";
			}else{
				cityHtml += "<input type='checkbox' class='citycheck' value=\""+el.cityid+"\">"+el.cityname+"&nbsp;&nbsp;";
			}
			num++;
		}
	});
	$(".selectCity").html(cityHtml);
});

$('input.save_btn').click(function() { 
	var pwd = $('input[name=password]').val();
	var repwd = $('input[name=repassword]').val();
	$('.city_id').val('');
	$('.citycheck').each(function(){
		if($(this).is(":checked")){
			var c_id = $(this).val();
			var city_id = $('.city_id').val();
			city_id = c_id + ',' + city_id;
			$('.city_id').val(city_id);
		}
	});
	
	if(pwd != repwd){
		callBackTips(0, '两次密码不一致');return;
	}else{
		$(this).tyAjax({
	        callBack: function(data) {
	            callBackTips(data.status, data.info, data.url);
	        }
	    });
	}
    
});
/* $('.save_btn').click(function(){
	
}); */
</script>
<include file="Common:footer" />